# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

import qsharp
from Microsoft.Quantum.Samples.BitFlipCode import (
    CheckBitFlipCodeCorrectsBitFlipErrors,
    CheckBitFlipCodeStateParity,
    CheckCanonBitFlipCodeCorrectsBitFlipErrors
)

"""First, we call the CheckBitFlipCodeStateParity operation defined in BitFlipCode.
This operation encodes into a bit-flip code, such that

	α |0〉 + β |1〉

is encoded into

	α |000〉 + β |111〉,

then ensures that the parity measurements Z₀Z₁ and
Z₁Z₂ both return the result Zero, indicating the eigenvalue
(-1)⁰ is positive.
This check is implemented as a sequence of assertions.
Since we are using a target machine which supports assertions,
this implies that if flow control continues past the operation
invocation, then all of the relevant checks have passed
"""
CheckBitFlipCodeStateParity.simulate()
print("\nParity check passed successfully!\n")

"""Next, we call the operation CheckBitFlipCodeCorrectsBitFlipErrors to check that the bit-flip code actually protects against bit-flip errors.

As before, this operation fails if an error is not corrected properly.
In the UnitTesting sample, we will see how to represent this pattern in terms of unit tests.
"""
CheckBitFlipCodeCorrectsBitFlipErrors.simulate()
print("Corrected all three bit-flip errors successfully!\n")

"""Finally, we repeat the check from above.

This time using operations and data types from the canon to allow us to represent other codes.
"""
CheckCanonBitFlipCodeCorrectsBitFlipErrors.simulate()
print("Corrected all three bit-flip errors successfully!\n")
